//
//  CustomImageView.m
//  ImageLoaderIndicatorDemo
//
//  Created by 卢小辉 on 15/10/16.
//  Copyright © 2015年 lulee007. All rights reserved.
//

#import "CustomImageView.h"
#import "SDWebImage/UIImageView+WebCache.h"
@implementation CustomImageView

@synthesize progressIndicatorView;
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype)initWithCoder:(NSCoder *)aDecoder{
    self=[super initWithCoder:aDecoder];
    if(self){
        progressIndicatorView=[[CircularLoaderView alloc]initWithFrame:self.bounds];
        [self addSubview:progressIndicatorView];
//        progressIndicatorView.frame=self.bounds;
        progressIndicatorView.autoresizingMask= UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
        
        NSURL *url=[[NSURL alloc ]initWithString:@"http://www.raywenderlich.com/wp-content/uploads/2015/02/mac-glasses.jpeg"];
        
        [self sd_setImageWithURL:url placeholderImage:nil options:SDWebImageCacheMemoryOnly progress:^(NSInteger receivedSize, NSInteger expectedSize) {
            
            //update progress here
            progressIndicatorView.progress=receivedSize*1.0f/(expectedSize*1.0f);
            
        } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
            // get image here
            self.image=image;
            [progressIndicatorView reveal];
        }];
        
    }
    return self;
}

@end
